<template>
  <div class="activet">
    <el-dialog title="激活邀约"
               :visible.sync="dialogVisible"
               width="30%"
               :before-close="handleClose">
      <el-form ref="form"
               :model="form"
               :rules="rules"
               label-width="80px">
        <el-form-item label="激活码"
                      prop="code">
          <el-input v-model="form.code"></el-input>
        </el-form-item>

      </el-form>
      <span slot="footer"
            class="dialog-footer">
        <el-button @click="$emit('closeDialog', false)">取 消</el-button>
        <el-button type="primary"
                   @click="shubmitActivet">确定激活</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { activeFunc } from '@/api/yywkapi'

export default {
  props: {
    dialogVisible: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      form: {
        code: '',
      },
      rules: {
        code: [
          { required: true, message: '请输入激活码', trigger: 'blur' },
          //   { min: 6, max: 6, message: '请输入6位激活码', trigger: 'blur' },
        ],
      },
    }
  },
  methods: {
    handleClose(done) {
      this.$emit('closeDialog', false)
      done()
    },
    shubmitActivet() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          activeFunc({
            token: this.$store.state.yywk.yywktoken,
            code: this.form.code,
          }).then((res) => {
            if (res.code === 0) {
              this.$emit('closeDialog', false)
              this.$message.success('激活成功')
              setTimeout(() => {
                this.$router.go(0)
              }, 400)
              this.$store.commit('yywk/SET_ACTIVETSTATUS', res.data)
              return
            }
            this.$message.error(res.msg)
            console.log('res.jihuo chengg ', res)
            // if (res.data.code === 200) {
            //   this.$message({
            //     message: res.data.msg,
            //     type: 'success',
            //   })
            //   this.$emit('closeDialog', false)
            //   this.$emit('refresh')
            // } else {
            //   this.$message({
            //     message: res.data.msg,
            //     type: 'error',
            //   })
            // }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
  },
}
</script>